import cookielib
import urllib
import urllib2

import urlopener
from secrets import SALSA_USERNAME, SALSA_PASSWORD

base_url = "https://salsa.wiredforchange.com"

def post_user_data(user_data):
    cookies = cookielib.CookieJar()
    client = urlopener.URLOpener()

    auth_data = {'email': SALSA_USERNAME, 'password': SALSA_PASSWORD}
    client.open(base_url + 'authenticate.sjs', urllib.urlencode(auth_data))

    if 'Chapter_Key' not in user_data:
        user_data['Chapter_Key'] = '9280'

    response = client.open(base_url + 'save', urllib.urlencode(user_data))
    return response.content

